"""
Filename: comp_stat_Rm_lumpsum.jl
Paper: Unemployment and the Distribution of Liquidity
Authors: Zach Bethune and Guillaume Rocheteau
Contact: bethune@rice.edu
Last Modified: 8/22/23
Purpose: holds function to compute steady-state comparative statics wrt Rm (money growth)
"""

###############################################################################
# Functions
###############################################################################
function Rm_sim(Rm_grid;mm::model_outcomes,parms::parmsmodel,mmts::model_moments)
    N=length(Rm_grid);
    Threads.@threads for i=1:N
        mm_new = deepcopy(mm); #copies ss eq in calibration
        py0=copy(mm.py); #initial guess of price
        Rf0=copy(mm.Rf);
        parms_new = deepcopy(parms);
        mmts_new = deepcopy(mmts);
        mm_new.Rm = copy(Rm_grid[i]);
        ss_new = nlsolve(x->mkt_clear_ss!(x;mm=mm_new,parms=parms_new,md=md,W_iter_tol=1e-10,Zmd=copy(mm_new.Zmd)),[py0,Rf0]);
        checkzero=mkt_clear_ss!(ss_new.zero;mm=mm_new,parms=parms_new,md=md,W_iter_tol=1e-10,Zmd=mm_new.Zmd);
        
        #compute moments
        mmts_new.G, mmts_new.G1, mmts_new.G0, mmts_new.gmi, mmts_new.Gmi, mmts_new.li_range, mmts_new.gls, mmts_new.Gls, mmts_new.ls_range, mmts_new.gwi, mmts_new.Gwi, mmts_new.wi_range, mmts_new.gini, mmts_new.liquid_share, mmts_new.liquid_to_income, mmts_new.gbonds_share, mmts_new.equity_share, mmts_new.wealth_to_income, mmts_new.liquid_prem = other_mmts(;mm=mm_new,parms=parms_new);

        #save data
        save(string("../model_data_gwaste/compstat_",i,".jld2"),"parms",parms_new,"mm",mm_new,"md",md,"mmts",mmts_new,"checkzero",checkzero);
    end
end

#END



